package exam.localdata;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.zip.DeflaterOutputStream;

/**
 * @author Xiongx
 * @version 1.0
 * @date 2021/3/31 13:12
 * @since JDK 1.8
 *
 * 集合数据处理
 */
public class ListDataServer {


    public static  <T> void  wirteList(String name, List<T> list){
        MapServer.addMap(name,list);
    }

    public static <T> List<T> getListByName(String name){
        Object obj=MapServer.getObjectBykey(name);
        if(obj==null){
            List<T> tList=new ArrayList<>();
            return tList;
        }else {
            return (List<T>) obj;
        }
    }


    public static <T> LocalPage<T> getLoclaPage(Integer page,Integer pageSize,List<T> tList){
        Integer start=(page-1)*pageSize;
        Integer end=start+pageSize;
        Integer  listSize=tList.size();
        if(start>listSize){
            start=listSize-1;
        }
        if(end>listSize){
            end=listSize;
        }
        System.out.println(start+"  "+end);
        List<T> newTList=tList.subList(start,end);
        LocalPage<T> localPage=new LocalPage();
        localPage.setCurrent(page);
        localPage.setData(newTList);
        localPage.setTotal(listSize);
        return localPage;
    }

}
